﻿using Microsoft.AspNetCore.Mvc;
using Qy.Core;
using Qy.Scenario;
using Qy.Web.Authorize;
using System.Threading.Tasks;

namespace Qy.Web.Areas.Api;

[Route("Api/[controller]/[action]")]
[Verify]
public class ConfigController : Base
{
    private readonly ConfigService _configService;
    public ConfigController(ConfigService configService)
    {
        _configService = configService;
    }

    [HttpGet]
    [ActionPermissionFilter(Permission = PermissionKeys.Config_Index)]
    public async Task<IActionResult> Index()
    {
        return Success(new { data = await _configService.GetSytemConfigAsync() });
    }

    [HttpPut]
    [ModelStateFilter]
    [ActionPermissionFilter(Permission = PermissionKeys.Config_Edit)]
    [Log(Name = "编辑系统配置")]
    public async Task<IActionResult> EditAsync([FromBody] SytemConfig data)
    {
        int res = await _configService.UpdateByNameAsync(data);
        return res > 0 ? Success("修改系统配置") : Fail("修改系统配置 ");
    }
}
